﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services.System;

namespace Simple.WebApi.Controllers.System
{
    [Route("api/ClassAlbum/[action]")]
    [ApiController]
    [Authorize]
    public class ClassAlbumController : ControllerBase
    {
        public readonly ClassAlbumService _parentChildTasksService;
        public ClassAlbumController(ClassAlbumService parentChildTasksService)
        {
            _parentChildTasksService = parentChildTasksService;
        }

        /// <summary>
        /// 班级相册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Page([FromQuery] ClassAlbumQueryPageInputModel model)
        {
            PageResultModel<ClassAlbumOutputModel> data = await _parentChildTasksService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 班级相册get
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Preview([FromQuery] IdInputModel models)
        {
            var data = await _parentChildTasksService.GetAsync(models.Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 班级相册创建
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromForm] ClassAlbumCreateOrUpdateModel model)
        {
            await _parentChildTasksService.AddAsync(model);
            return AppResult.Status200OK("发布成功");
        }

        /// <summary>
        /// 班级相册修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Edit([FromForm] ClassAlbumCreateOrUpdateModel model)
        {
            await _parentChildTasksService.UpdateAsync(model);
            return AppResult.Status200OK("更新成功");
        }

        /// <summary>
        /// 移动端班级相册创建
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> MoveAdd([FromBody] ClassAlbumMoveCreateOrUpdateModel model)
        {
            await _parentChildTasksService.MoveAddAsync(model);
            return AppResult.Status200OK("发布成功");
        }

        /// <summary>
        /// 移动端班级相册修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> MoveEdit([FromBody] ClassAlbumMoveCreateOrUpdateModel model)
        {
            await _parentChildTasksService.MoveUpdateAsync(model);
            return AppResult.Status200OK("更新成功");
        }


        /// <summary>
        /// 班级相册删除
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromBody] List<IdInputModel> models)
        {
            await _parentChildTasksService.DeleteAsync(models.Select(m => m.Id));
            return AppResult.Status200OK("删除成功");
        }
    }
}
